#画图R base plot
rm(list = ls())
#hist直方图 从总到分展现数据分布
count <- read.csv("./RNAseq/count.csv",sep = " ")
png("直方图.png",width=600,height=600)
a <-count$PTB008D
h0<-a[a <10000 ]
h1<-a[a <10000 ]
h1 <- h1[h1>0]
h2 <- a[a<100]
h2 <- h2[h2>0]
h3 <- a[a<10]
h3 <- h3[h3>0]
h4 <- a[a<1]
h4 <- h4[h4>0]
par(mfrow=c(3,2))
p1 <-hist(count$PTB008D ,breaks = 20,labels=TRUE, col = "lightgreen")
p2 <- hist(h0,breaks = 20,labels=TRUE, col = "lightgreen",main ="小于10000数据" )
p3 <- hist(h1,breaks = 20,labels=TRUE, col = "lightgreen",main ="小于10000数据（除去=0的24674个）" ) 
p4 <- hist(h2,breaks = 20,labels=TRUE, col = "lightgreen",main ="小于100数据（除去=0的24674个）") 
p5 <- hist(h3,breaks = 20,labels=TRUE, col = "lightgreen",main ="小于10数据（除去=0的24674个）")
p6 <- hist(h4,breaks = 20,labels=TRUE, col = "lightgreen",main ="小于1数据（除去=0的24674个）")
dev.off()
#层次聚类 树状图
ad <- read.csv("./ad.csv")
jpeg("树状图.jpg",width=1000,height=300)
row.names(ad) <- ad[,2]
ad <- ad[,-(1:2)]
distance <- dist(ad)
tree<-hclust(distance,method="average")
plot(tree)
dev.off()
#火山图
library(ggplot2)
load("./data/volcano.RData")
prostat$color <- ifelse(prostat$P < 0.05 & abs(prostat$FC) >= log2(1.2),
                        ifelse(prostat$FC > log2(1.2), 'up', 'down'),
                        'no')

p <-  ggplot(prostat, aes(x = FC, y = -log10(P),colour =color)) +
  geom_point() + 
  geom_hline(yintercept=-log10(0.05),linetype=4)+
  geom_vline(xintercept=c(-log2(1.2),log2(1.2)),linetype=4)+
  scale_color_manual(values = c("blue", "grey", "red"))+
  labs(x="log2 fold change")+
  theme_bw()+
  ggtitle("火山图")
ggsave("火山图.jpg", p, width = 8, height = 6, dpi = 300)


